<?php
//include APPLICATION_PATH."/models/base/ProvinceBase.php";
/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
class Model_Report1{
    
    public function fetchAllReport(){
        $db = Zend_Db_Table::getDefaultAdapter();
        //$select=$db->select()
               // ->from('province')
                //->//where('status=1');
        $stmt=$db->query("SELECT t1.*, t2.name as province_name, t3.name as district_name,t1.birthday as birthday, t1.ability_sell FROM `agent`  as t1
                            LEFT JOIN `province`  as t2 ON t1.province_id = t2.id
                            LEFT JOIN `district`  as t3 ON t1.district_id = t3.id
                            LEFT JOIN `user`      as t4 ON t1.user_id = t4.id
                            WHERE t1.agent_cat_id = 1 and t1.agent_status!=3");
        $rows = $stmt->fetchAll(PDO::FETCH_CLASS);
        $stmt->closeCursor();
        $entries   = array();
        foreach ($rows as $row) {
            //$ability=  GlobalLib::query('select SUM(quantity) as ability from order_detail where order_status_id =2 and agent_id=?',$row->id);
            if($row->birthday==null){
                $ngaysinh="";
            } else {
                $ngaysinh=$row->birthday;
            }
//            if($ability[0]==null){
//                $ability_agent="";
//            } else {
//                $ability_agent=$ability[0]['ability'];
//            }
            $array=array(
              'id'=>  $row->id,
              'name'=>$row->name,
              'province_name'=>$row->province_name,
              'legal_capital'=>$row->legal_capital,
              'experience'=>$row->experience,  
              'birthday'=>  GlobalLib::viewDate($ngaysinh),
              'representavie'=>$row->representavie,
               'person'=>$row->person,
                'ability_agent'=>$row->ability_sell,
                'ability_archive'=>$row->ability_archive,
                'ability_transport'=>$row->ability_transport
            );
            array_push($entries,$array);
        }
        return $entries;
    }
}

